package com.yang.controller;

import com.yang.limit.annotation.RequestLimit;
import com.yang.limit.constant.RequestLimitType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试限流控制器
 *
 * @author: jacklin
 * @since: 2022/5/10 14:20
 */
@RestController
@RequestMapping()
public class RequestLimitController {

    /**
     * 测试AOP拦截 令牌桶 限流
     *
     * @return 返回结果
     */
    @RequestLimit(type = RequestLimitType.TOKEN_BUCKET, limitCount = 20, limitPeriodCount = 1, period = 3000)
    @GetMapping("/token-bucket-test")
    public String tokenBucketTest() {
        return "【" + RequestLimitType.TOKEN_BUCKET.getDesc() + "】限流 - 接口返回";
    }

    /**
     * 测试AOP拦截 漏桶 限流
     *
     * @return 返回结果
     */
    @RequestLimit(type = RequestLimitType.LEAKY_BUCKET, limitCount = 100, limitPeriodCount = 10, period = 3000)
    @GetMapping("/leaky-bucket-test")
    public String leakyBucketTest() {
        return "【" + RequestLimitType.LEAKY_BUCKET.getDesc() + "】限流 - 接口返回";
    }


}
